import json
import requests
from basic.base import BaseRequest
from config import ENV

class URL:
    MEMBER_LIST = "adminapi/member/member"
    MEMBER_ADD = "adminapi/member/member"
    MEMBER_MODIFY = "adminapi/member/member"
    MEMBER_MESSAGE = "adminapi/member/member"
    MEMBER_LABEL_LIST = "adminapi/member/label"
    MEMBER_LABEL_ADD = "adminapi/member/label"
    # MEMBER_LABEL_MODIFY = "adminapi/member/label"

class Member(BaseRequest,URL):
    def member_list(self,keyword=None,register_type=None,label=None,register_channel=None,level=None,**kwargs):
        """ 会员列表、支持条件查询"""
        """
        :param keyword: 手机、邮箱、姓名、昵称
        :param register_type: 注册来源
        :param label: 会员标签
        :param register_channel:
        :param level: 会员等级
        :return: response.json()
        """
        data = {
                    'page': '1',
                    'limit': '10',
                    'keyword': keyword,
                    'register_type': register_type,
                    'member_label': label,
                    'register_channel': register_channel,
                    'member_level': level,
                    **kwargs
        }
        return self._get(url=self.MEMBER_LIST,params=data)

    def member_add(self,name,member_id=None,member_no = None,init_member_no = None,mobile = None,password = None):
        """ 会员添加"""
        data = {
                    "member_id": member_id,
                    "nickname": name,
                    "member_no": member_no,
                    "init_member_no": init_member_no,
                    "mobile": mobile,
                    "password": password,
                    "password_copy": password
        }
        return self._post(url=self.MEMBER_ADD,data=data)

    def member_modify(self,member_id,field,value):
        """ 会员编辑"""
        M_URL = self.MEMBER_MODIFY + f"/{member_id}/{field}"
        data= {"member_id":member_id,"field":field,"value":value }
        return self._put(url=M_URL,data=data)

    def member_massage(self,member_id):
        """ 会员信息"""
        M_URL = self.MEMBER_MESSAGE + f"/{member_id}"
        return self._get(url=M_URL)

    def member_label_list(self,label_name):
        """ 会员标签列表"""
        M_URL = self.MEMBER_LABEL_LIST + f"/{label_name}"
        return self._get(url=M_URL)

    def member_label_add(self,label_name):
        """ 会员标签添加"""
        M_URL = (self.MEMBER_LABEL_ADD+ f"/{label_name}")
        data={"label_name": label_name}
        return self._post(url=M_URL,data=data)

    # def member_label_modify(self,label_id, label_name, intro, sort):
    #     """ 会员标签编辑"""
    #     M_URL = (self.MEMBER_LABEL_MODIFY + f"/{label_id}")
    #     data={
    #             "label_id": label_id,
    #             "label_name": label_name,
    #             'memo': intro,
    #             'sort': sort
    #     }
    #     return self._put(url=M_URL,data=data)
    #
    # def member_label_delete(self):
    #     """ 会员标签删除"""
    #     data={
    #         "method" : "DELETE",
    #         "url" : f"http://124.70.39.201/adminapi/member/label/{id}",
    #         "headers" : {"token":self.token},
    #     }
    #     r=requests.request(**data)
    #     return r.json()
    #
    # def member_level_list(self):
    #     """ 会员等级列表"""
    #     data={
    #         "method" : "GET",
    #         "url":"http://124.70.39.201/adminapi/member/level?page=1&limit=10&level_name=",
    #         "headers" : {"token":self.token},
    #     }
    #     r=requests.request(**data)
    #     return r.json()
    #
    # def member_level_add(self):
    #     """ 会员等级添加"""
    #     data = {
    #         "method": "GET",
    #         "url": "http://124.70.39.201/adminapi/member/dict/benefits",
    #         "headers": {"token": self.token},
    #     }
    #     r = requests.request(**data)
    #     return r.json()
    #
    # def member_level_config_growth_rule(self):
    #     """ 会员等级成长规则配置查询"""
    #     data = {
    #         "method": "GET",
    #         "url": "http://124.70.39.201/adminapi/member/dict/growth_rule",
    #         "headers": {"token": self.token},
    #     }
    #     r = requests.request(**data)
    #     return r.json()
    #
    # def member_account_balance(self):
    #     """ 会员账户余额"""
    #     data = {
    #         "method": "GET",
    #         "url": "http://124.70.39.201/adminapi/member/account/balance?page=1&limit=10&keywords=&from_type=&create_time=&mobile=&member_id=0&balance_type=",
    #         "headers": {"token": self.token},
    #     }
    #     r = requests.request(**data)
    #     return r.json()
    #
    # def member_account_commission(self):
    #     """ 会员账户佣金"""
    #     data = {
    #         "method": "GET",
    #         "url": "http://124.70.39.201/adminapi/member/account/commission?page=1&limit=10&keywords=&from_type=&create_time=&mobile=&member_id=0",
    #         "headers": {"token": self.token},
    #     }
    #     r = requests.request(**data)
    #     return r.json()

if __name__ == '__main__':
    member = Member()
